/**
 * Created by dukes on 2016/3/5.
 */
class MedalCleanPanel extends eui.Component {
    public constructor() {
        super();
        this.skinName = "skins.scene.MedalCleanSkin";
        this.addEventListener(egret.Event.ADDED_TO_STAGE,this.onAdded, this );
        this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.onRemoved, this);
    }

    public onClean1(evt:egret.TouchEvent){
        window["__clearMedal"](false);
    }

    public onClean2(evt:egret.TouchEvent){
        window["__clearMedal"](true);
    }

    private onClose(evt:egret.TouchEvent){
        SoundMgr.getInstance().playEffect(SoundMgr.BTN);
        // var logo = GuildMgr.getInstance().guildLogo;
        // if( logo.tempAttack != 0 || logo.tempDefense != 0) {
        //     RemindPanel.getInstance().showContent("您要保存本次擦拭效果吗",this, this.onOk, this.onCancel);
        // }else{
            this.hide();
        // }
    }

    private onCancel(){
        window["__saveClaerMedal"](false);
        this.hide();
    }

    private onOk(evt:egret.TouchEvent){
        // var logo = GuildMgr.getInstance().guildLogo;
        // if( logo.tempAttack != 0 || logo.tempDefense != 0) {
        //     window["__saveClaerMedal"](true);
        // }else{
            ShowHint("您还未擦拭族徽呢");
        // }
        this.hide();
    }

    private onAdded(evt:egret.Event){
        this.img_close.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClose, this);
        this.img_yes.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onOk, this);
        this.img_clean_1.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClean1, this);
        this.img_clean_2.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClean2, this);
        this.updateDisplay();
    }
    private onRemoved(evt:egret.Event){
        this.img_close.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onClose, this);
        this.img_yes.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onOk, this);
        this.img_clean_1.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onClean1, this);
        this.img_clean_2.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onClean2, this);
    }
    public updateDisplay(){
        // var logo = GuildMgr.getInstance().guildLogo;
        // if( logo){
        //     var arr = [];
        //     var temp = {
        //         text:"当前属性\r攻击+"+(logo.attrAttack+logo.addtionAttack),
        //         style:{
        //             "textColor": 0xffffff,
        //             "size":16,
        //         }
        //     };
        //     arr.push(temp);

        //     if( logo.tempAttack != 0){
        //         temp = {
        //             text:" "+(logo.tempAttack > 0 ? "+"+logo.tempAttack  : logo.tempAttack) +"",
        //             style:{
        //                 "textColor": logo.tempAttack > 0 ? 0x00ff00 : 0xff0000,
        //                 "size":16,
        //             }
        //         };
        //         arr.push(temp);
        //     }

        //     temp = {
        //         text:"\r防御+"+(logo.attrDefense+logo.addtionDefense),
        //         style:{
        //             "textColor": 0xffffff,
        //             "size":16,
        //         }
        //     };

        //     arr.push(temp);

        //     if( logo.tempDefense != 0){
        //         temp = {
        //             text:" "+ (logo.tempDefense > 0 ? "+"+logo.tempDefense  : logo.tempDefense) + "",
        //             style:{
        //                 "textColor": logo.tempDefense > 0 ? 0x00ff00 : 0xff0000,
        //                 "size":16,
        //             }
        //         };
        //         arr.push(temp);
        //     }
        //     this.lab_prop.textFlow = arr;
        // }
        // var contriTime = Model.userExt.scrubContributionTimes;
        // if( contriTime >= 4){
        //     contriTime = 4;
        // }
        // this.lab_hair.text = "贡献："+GuildMgr.Clean_Cost[contriTime][0];

        // var diamondTime = Model.userExt.scrubDiamondTimes;
        // if( diamondTime >= 4){
        //     diamondTime = 4;
        // }
        // this.lab_diamond.text = GuildMgr.Clean_Cost[ diamondTime ][1]+"";
    }

    public show(){
        if( !DisplayController.instance().stage) return;
        DisplayController.instance().addToAlert(GameConst.GrayMask);
        DisplayController.instance().addToAlert(this);
    }

    public hide(){
        DisplayController.instance().removeFromAlert(GameConst.GrayMask);
        DisplayController.instance().removeFromAlert(this);
    }

    public measure() {
        super.measure();
        this.x = GameConst.StageW - this.measuredWidth >> 1;
        this.y = GameConst.StageH - this.measuredHeight >> 1;
    }

    public lab_prop:eui.Label;
    private img_clean_1:eui.Image;
    private img_clean_2:eui.Image;
    public img_yes:eui.Image;
    private img_close:eui.Image;
    public lab_hair:eui.Label;
    private lab_diamond:eui.Label;
    public partAdded(name:string, instance:any) {
        super.partAdded(name, instance);
        if (name == "lab_prop") {
            this.lab_prop = instance;
        } else if (name == "img_clean_1") {
            this.img_clean_1 = instance;
        }else if (name == "img_clean_2") {
            this.img_clean_2 = instance;
        }else if (name == "img_yes") {
            this.img_yes = instance;
        }else if (name == "img_close") {
            this.img_close = instance;
        }else if (name == "lab_hair") {
            this.lab_hair = instance;
        }else if (name == "lab_diamond") {
            this.lab_diamond = instance;
        }
    }
    private static _instance:MedalCleanPanel;
    public static getInstance():MedalCleanPanel{
        if( MedalCleanPanel._instance == null)
            MedalCleanPanel._instance = new MedalCleanPanel();
        return MedalCleanPanel._instance;
    }
}